﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}
@section Content{
    <style>
        .topPanel {
            height: 95px;
        }

            .topPanel .search {
                padding-top: 10px;
            }
    </style>
}
<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
            @*<a class="btn btn-default" onclick="$.reload()">自拓场地todo</a>*@
            @*<a class="btn btn-default" onclick="btn_highSeas()">公海</a>*@
        </div>
        @*<div class="btn-group">
                <a id="NF-add" authorize="yes" class="btn btn-primary dropdown-text" onclick="btn_add()"><i class="fa fa-eraser"></i>添加按钮</a>
            </div>
            <div class="operate">
                <ul class="nav nav-pills">
                    <li class="first">已选中<span>1</span>项</li>
                    <li><a id="NF-edit" authorize="yes" onclick="btn_edit()"><i class="fa fa-pencil-square-o"></i>修改按钮</a></li>
                    <li><a id="NF-delete" authorize="yes" onclick="btn_delete()"><i class="fa fa-trash-o"></i>删除按钮</a></li>
                </ul>
                <a href="javascript:;" class="close"></a>
            </div>
            <script>$('.toolbar').authorizeButton()</script>*@
    </div>
    @*<div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control" placeholder="请输入要查询活动名称" style="width: 200px;">
                        <span class="input-group-btn">
                            <button id="btn_search" type="button" class="btn  btn-primary"><i class="fa fa-search"></i></button>
                        </span>
                    </div>
                    <div id="search_orderState" class="btn-group btn-group-sm" role="group">
                        <input type="hidden" id="orderstate" name="orderstate" value="" />
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 0)">订单指派</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 1)">场地推荐</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 2)">带看场地</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 3)">意向场地确认</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 4)">价格谈判</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 5)">场地预定</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 6)">签订合同</button>
                        <button type="button" class="btn btn-default" onclick="search_orderState(this, 7)">订单结束</button>
                    </div>
                </td>
            </tr>
        </table>
    </div>*@
</div>

<div class="gridPanel">
    <table id="gridList"></table>
    <div id="gridPager"></div>
</div>


<script>
    // from page type
    var pageType = $.request("type");

    $(function () {
        gridList();
    })
    function gridList() {
        var $gridList = $("#gridList");
        var flowStateArr = ['订单指派', '场地推荐', '带看场地', '意向场地', '价格谈判', '场地预定', '签订合同', '订单完成'];
        var flowOrderStateArr = ['等待确认', '通过', '驳回'];
        var stateArr = ['无效', '有效', '信息不完整'];

        $gridList.dataGrid({
            url: "/ClientManager/ClientInfos/GetMyAuditGridJson",
            height: $(window).height() - 176,
            colModel: [
                { label: '客户订单场地推荐表标识', name: 'F_SiteClientOrderRecommendId', hidden: true },
                { label: '订单编号', name: 'F_OrderId', width: 50, align: 'left', hidden: true },
                { label: '档期状态', name: 'F_ScheduleState', width: 100, align: 'left' },
                { label: '场地', name: 'SiteTitle', width: 80, align: 'left' },
                { label: '空间', name: 'SpaceTitle', width: 80, align: 'left' },

                {
                    label: '操作', name: 'F_SiteClientOrderRecommendId', width: 120, align: 'left',
                    formatter: function (cellvalue, options, rowObject) {
                        var html = '<div class="btn-group btn-group-xs" style="margin-top:5px;">';
                        html += '   <button type="button" class="btn btn-link" onclick="btn_audit(\'' + cellvalue + '\', 0)">审核</button>';
                        html += '</div>';

                        return html;
                    }
                }
            ],
            postData: {
                environment: 1,
                type: pageType,
                orderId: 'c3e5c5e9-a2e0-4639-947d-24e6cbb01ae5'
            },
            pager: "#gridPager",
            sortname: 'F_CreatorTime',
            viewrecords: true
        });
        $("#btn_search").click(function () {
            var queryJson = {
                keyword: $("#txt_keyword").val(), orderstate: $("#orderstate").val()
            };
            $gridList.jqGrid('setGridParam', {
                postData: { queryJson: JSON.stringify(queryJson) },
            }).trigger('reloadGrid');
        });
    }

    //审核
    function btn_audit(id) {
        $.modalConfirm('确认是否有档期？', function (flag) {
            var state;
            if (flag) {
                state = 1;
            } else {
                state = 2;
            }

            $.submitForm({
                url: "/ClientManager/ClientInfos/AuditOrderState?siteClientOrderRecommendId=" + id + "&state=" + state,
                param: {},
                success: function (data) {
                    $.currentWindow().$("#gridList").trigger("reloadGrid");
                }
            });
        }, { btn: ['是', '否'] });

        
        // debugger

        //$.modalOpen({
        //    id: "Form",
        //    title: "修改 ClientOrder",
        //    url: "/ClientManager/ClientInfos/AuditOrderState?F_SiteClientOrderRecommendId=" + id,
        //    width: "700px",
        //    height: "520px",
        //    callBack: function (iframeId) {
        //        top.frames[iframeId].submitForm();
        //    }
        //});
    }

    function btn_add() {


        $.modalOpen({
            id: "Form",
            title: "新增 ClientOrder",
            url: "/OrderFlowManage/ClientOrder/Form",
            width: "500px",
            height: "300px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_edit() {
        var keyValue = $("#gridList").jqGridRowValue().F_Id;
        $.modalOpen({
            id: "Form",
            title: "修改 ClientOrder",
            url: "/OrderFlowManage/ClientOrder/Form?keyValue=" + keyValue,
            width: "700px",
            height: "520px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }
    function btn_delete() {
        $.deleteForm({
            url: "/OrderFlowManage/ClientOrder/DeleteForm",
            param: { keyValue: $("#gridList").jqGridRowValue().F_Id },
            success: function () {
                $.currentWindow().$("#gridList").trigger("reloadGrid");
            }
        })
    }

    // 让单
    function btn_giveSingle(keyValue) {
        $.modalOpen({
            id: "GiveSingle",
            title: "让单",
            url: "/OrderFlowManage/ClientOrder/GiveSingle?keyValue=" + keyValue,
            width: "700px",
            height: "420px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    // 踢单
    function btn_giveSignOutSingle(keyValue) {
        $.modalOpen({
            id: "GiveSingle",
            title: "踢单",
            url: "/OrderFlowManage/ClientOrder/SignOutSingle?keyValue=" + keyValue,
            width: "700px",
            height: "420px",
            callBack: function (iframeId) {
                top.frames[iframeId].submitForm();
            }
        });
    }

    // 公海
    function btn_highSeas() {
        var id = RndNum();
        console.log("RndNum: " + id);
        $.addTab({
            href: '/OrderFlowManage/ClientOrder/HighSeas',
            text: '公海',
            id: id,
            index: 998
        });
    }

    function btn_detail(id, type) {
        $.addTab({
            href: '/OrderFlowManage/ClientOrder/Details?pageType=' + pageType + '&orderid=' + id + '&type=' + type,
            text: '订单详细',
            id: id,
            index: 999
        });
    }

    function btn_statedetail(id, type) {
        if (type == 0) {
            $.modalOpen({
                id: "GiveSingle",
                title: "订单指派",
                url: "/OrderFlowManage/ClientOrder/GiveSingle?orderid=" + id,
                width: "700px",
                height: "420px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitOrderForm();
                }
            });
        } else {
            btn_detail(id, type);
        }
    }

    function search_orderState(dom, state) {
        if ($(dom).hasClass("active")) {
            $("#orderstate").val('');
            $("#search_orderState .btn").removeClass("active");
        } else {
            $("#orderstate").val(state);
            $("#search_orderState .btn").removeClass("active");
            $(dom).addClass("active");
        }
    }
</script>
